/************************************************************************
 * @file AbstractMenuManager.cpp
 * @author Ian Chen
 * @version 1.0
 *
 * @section LICENSE
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details at
 * http://www.gnu.org/licenses/lgpl.html
 *
 ************************************************************************/
#include <pluginui/manager/AbstractMenuManager.h>

namespace antu
{
namespace plugin
{
namespace ui
{
AbstractMenuManager::AbstractMenuManager()
{
}

QMenu *AbstractMenuManager::menu(const QString &name)
{
    return this->menu(name, name);
}

QMenu *AbstractMenuManager::menu(const QString &name, const QString &title, const QIcon &icon)
{
    map<QString, QMenu*>::iterator iter = this->m_oMainMenuSections.find(name);
    if (iter == this->m_oMainMenuSections.end())
    {
        QMenu* pMenu = this->createMenu(name, title, icon);
        if (pMenu != nullptr)
        {
            this->m_oMainMenuSections.insert(pair<QString, QMenu*>(name, pMenu));
            iter = this->m_oMainMenuSections.find(name);
        }
        else
            return nullptr;
    }

    return iter->second;
}

bool AbstractMenuManager::hasMenus()
{
    return this->m_oMainMenuSections.size() > 0;
}
}
}
}
